<?php
/*
 * @Date: 2021-05-08 11:32:40
 * @Author: yukun
 * @LastEditors: yukun
 * @LastEditTime: 2021-05-08 12:51:37
 * @FilePath: /design-patterns-study/观察者模式/Go.php
 * @Description: 本文件主要功能为：
 */

require "HobbyConstants.php";
require "UserSubject.php";
require "SecrityObserver.php";
require "AdObserver.php";

$hobbyArr = HobbyConstants::getConstants();
$hobbyArr = array_values($hobbyArr);

$userSubject = new UserSubject();

$userSubject->setLoginNum(rand(0, 5));
$userSubject->setHobby($hobbyArr[rand(0, 2)]);

$ob1 = new SecrityObserver();
$ob2 = new AdObserver();

$userSubject->attach($ob1);
$userSubject->attach($ob2);

$userSubject->login();

$userSubject->detach($ob1);

$userSubject->login();